package com.app.community.mapper;

import com.app.community.dto.PersonDTO;
import com.app.community.model.entity.Question;
import com.app.community.model.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Date 2020/10/28 22:31
 **/
@Mapper
public interface PersonMapper {

    @Results({
            @Result(column = "cover_pic",property = "coverPic"),
            @Result(column = "nick_name",property = "nickName")
    })
    @Select({"select cover_pic,introduction,nick_name,avatar from user where user_id = #{userId}"})
    User selectPerson(@Param("userId") String userId);

    @Results({
            @Result(column = "question_id",property = "questionId"),
            @Result(column = "cover_pic",property = "coverPic")
    })
    @Select({"select title,summary,cover_pic,date,question_id from question where creator = #{userId}"})
    List<Question> selectQuestion(@Param("userId")String userId);

    /**
     * 删除问题，并确认是本人操作
     */
    @Delete({"delete from question where question_id = #{questionId} and creator = #{userId}"})
    void deleteQuestion(@Param("questionId")Long questionId,@Param("userId")String userId);

    /**
     * 删除评论
     */
    @Delete({"delete from comment where question_id = #{questionId}"})
    void deleteComment(@Param("questionId")Long questionId);
}
